package dk.au.cs.bdsi.sms.domain;

import javax.xml.bind.annotation.XmlEnumValue;

/**
 * Defines the possible encodings of the message payload of a {@link Sms},
 * including meta-data such as the maximum possible message length (ignoring
 * message chaining) for a given encoding.<br/>
 * <br/>
 * The details of the possible character encodings are detailed in GSM Recommendation 03.38
 * as outlined on <a href="http://en.wikipedia.org/wiki/GSM_03.38">GSM 03.38 at Wikipedia</a>.<br/>
 * <br/>
 * The GSM-7 alphabet is also detailed at <a href="http://www.dreamfabric.com/sms/default_alphabet.html">dreamfabric.com</a>.
 * 
 */
public enum MessageEncoding {
	
	/**
	 * 7-bit character encoding making it possible to send 160 characters in a single
	 * message. 
	 */
	@XmlEnumValue(value = "GSM-7")
	GSM7,
	
	/**
	 * 8-bit data encoding, which treats the message payload as raw data. Thus any intended
	 * alphabet encoding is user supplied. Thus you can send 140 octets of data / characters.
	 */
	@XmlEnumValue(value = "GSM-8")
	GSM8,
	
	/**
	 * 16-bit standard UTF-16 character encoding, making it possible to send 70 characters.
	 */
	@XmlEnumValue(value = "UTF-16")
	UTF16;
	
	public final static int MaximumPayloadSize = 140 /* octets */ * 8 /* bits */; // = 1120 bits
	
	/**
	 * The number of bits a single character in the given encoding
	 * consumes.
	 * 
	 * @return Number of bits for a single character
	 */
	public int getCharacterBitSize() {
		switch (this) {
		case GSM7: return 7;
		case GSM8: return 8;
		case UTF16: return 16;
		default: return -1;
		}
	}
	
	/**
	 * Number of characters a single message can contain in
	 * the given encoding.
	 * 
	 * @return Number of characters a single message can contain
	 */
	public int getMaximumCharacters() {
		switch (this) {
		case GSM7: return 160;	// = 1120 / 7
		case GSM8: return 140;	// = 1120 / 8
		case UTF16: return 70;	// = 1120 / 16
		default: return -1;
		}
	}
}
